/**
 * 
 */
package com.genuine.hyjj;

import java.io.IOException;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;

/**
 * @author Administrator
 *
 */
public class MyLocation extends Activity {

	TextView txt_location =null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mylocation);
		txt_location=(TextView)findViewById(R.id.txt_location);
		txt_location.setText(getLocationInfo());
	}
	public String getLocationInfo() {
		String result = "";
		LocationManager locationmanager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
		locationmanager.requestLocationUpdates(
				LocationManager.NETWORK_PROVIDER, 0, 0,
				new MyLocationListener());
		Location location = locationmanager
				.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
		Geocoder gc = new Geocoder(this);
		List<Address> addresses = null;
		try {
			addresses = gc.getFromLocation(location.getLatitude(),
					location.getLongitude(), 1);
		} catch (IOException e) {
			
		}
		if (addresses.size() > 0) {
			result = addresses.get(0).getLocality();
		}
		return result;
	}
	class MyLocationListener implements LocationListener {

		public void onLocationChanged(Location arg0) {

		}

		public void onProviderDisabled(String arg0) {

		}

		public void onProviderEnabled(String arg0) {

		}

		public void onStatusChanged(String arg0, int arg1, Bundle arg2) {

		}

	}

}
